import Cookies from 'js-cookie'

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    withoutAnimation: false,
    hide: false
  },
  device: 'desktop',
  size: Cookies.get('size') || 'medium',
  // app 类型
  appTypes: [
    { value: 0, label: '微信', },
    { value: 1, label: 'qq', },
    { value: 2, label: '抖音', },
    { value: 3, label: '百度', },
    { value: 4, label: '支付宝', },
    { value: 5, label: '快手', },
    { value: 6, label: 'app', },
    { value: 7, label: '内置', }
  ],
  // 标签回显样式
  btnTypeList: [
    { alue: "default", label: "默认", },
    { value: "primary", label: "主要", },
    { value: "success", label: "成功", },
    { value: "info", label: "信息", },
    { value: "warning", label: "警告", },
    { value: "danger", label: "危险", },
    { value: "error", label: "错误", }
  ],
  navTypeList: [
    { value: 'navigateTo', label: `打开新页`, },
    { value: 'switchTab', label: `跳转首页`, },
    { value: 'redirectTo', label: `重定向页面`, },
    { value: 'reLaunch', label: `重启到首页`, },
  ],
  // 打开类型
  goTypeList: [
    { value: 'inner', label: '内链', },
    { value: 'outmp', label: '外部小程序', },
    { value: 'copy', label: '复制内容', },
    { value: 'webview', label: 'webview', },
    { value: 'appOpenBrowserH5', label: 'app打开浏览器H5', },
    { value: 'androidAppOpenApp', label: 'Android打开app', },
    { value: 'iOSAppOpenApp', label: 'iOS打开app', },
    { value: 'h5OpenApp', label: 'h5唤起app', },
    { value: 'h5OpenH5', label: 'h5跳转其他h5', },
    { value: 'copyAndAndroidAppOpenApp', label: '复制且Android打开app', },
    { value: 'copyAndIOSAppOpenApp', label: '复制且iOS打开app', }
  ],
  // 类型banner-轮播 popup-弹窗 float-浮窗
  imageTypeList: [
    { value: 'banner', label: `轮播`},
    { value: 'popup', label: `弹窗`},
    { value: 'float', label: `浮窗`},
  ],
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    if (state.sidebar.hide) {
      return false;
    }
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  SET_SIZE: (state, size) => {
    state.size = size
    Cookies.set('size', size)
  },
  SET_SIDEBAR_HIDE: (state, status) => {
    state.sidebar.hide = status
  }
}

const actions = {
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  setSize({ commit }, size) {
    commit('SET_SIZE', size)
  },
  toggleSideBarHide({ commit }, status) {
    commit('SET_SIDEBAR_HIDE', status)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
